package cn.hill4j.tool.spring.ext.mvc;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpInputMessage;

import java.io.IOException;
import java.io.InputStream;
/**
  * ClassName: DecHttpInputMessage
  * Description: body可重写HttpInputMessage
  * @author hillchen
  * Date: 2023/8/13
  * @version: 1.0
  */
public class DecHttpInputMessage implements HttpInputMessage {
    /**
     * 原始body的HttpInputMessage
     */
    private HttpInputMessage httpInputMessage;
    /**
     * 重写的body的InputStream
     */
    private InputStream bodyInputStream;

    /**
     * @author hillchen
     * Description: 构造方法
     * Date: 2023/8/13 00:35
     * @param httpInputMessage 原始body的HttpInputMessage
     * @param bodyInputStream 重写的body的InputStream
     **/
    public DecHttpInputMessage(HttpInputMessage httpInputMessage, InputStream bodyInputStream) {
        this.httpInputMessage = httpInputMessage;
        this.bodyInputStream = bodyInputStream;
    }

    @Override
    public InputStream getBody() throws IOException {
        return bodyInputStream;
    }

    @Override
    public HttpHeaders getHeaders() {
        return httpInputMessage.getHeaders();
    }
}
